' Compatibility codes for ASP Report Maker
Const EW_PROJECT_NAME = "hrcompany" ' Project Name
Const EW_MAX_EMAIL_RECIPIENT = 3
' Language settings
Const EW_LANGUAGE_FOLDER = "lang/"
Dim EW_LANGUAGE_FILE(0)
EW_LANGUAGE_FILE(0) = Array("en", "", "english.xml")
Const EW_LANGUAGE_DEFAULT_ID = "en"
Dim EW_SESSION_LANGUAGE_FILE_CACHE
EW_SESSION_LANGUAGE_FILE_CACHE = EW_PROJECT_NAME & "_LanguageFile_" ' Language File Cache
Dim EW_SESSION_LANGUAGE_CACHE
EW_SESSION_LANGUAGE_CACHE = EW_PROJECT_NAME & "_Language_" ' Language Cache
Dim EW_SESSION_LANGUAGE_ID
EW_SESSION_LANGUAGE_ID = EW_PROJECT_NAME & "_LanguageId" ' Language ID
'
' *** DO NOT CHANGE BELOW
'
' Init language object
Set Language = new cLanguage
'
' --------------------------------------
'  Language class for ASPMaker 8 (begin)
'
Class cLanguage
	Dim LanguageId
	Dim objDOM
	' Class initialize
	Private Sub Class_Initialize
		' Set up file list
		Call LoadFileList()
		' Set up language id
		If Request.QueryString("language").Count > 0 Then
			LanguageId = CStr(Request.QueryString("language"))
			Session(EW_SESSION_LANGUAGE_ID) = LanguageId
		ElseIf Session(EW_SESSION_LANGUAGE_ID) <> "" Then
			LanguageId = Session(EW_SESSION_LANGUAGE_ID)
		Else
			LanguageId = EW_LANGUAGE_DEFAULT_ID
		End If
		gsLanguage = LanguageId
		Call Load(LanguageId)
	End Sub
	' Terminate
	Private Sub Class_Terminate()
		Set objDOM = Nothing
	End Sub
	' Load language file list
	Private Sub LoadFileList()
		Dim i
		If IsArray(EW_LANGUAGE_FILE) Then
			For i = 0 to UBound(EW_LANGUAGE_FILE)
				EW_LANGUAGE_FILE(i)(1) = LoadFileDesc(Server.MapPath(EW_LANGUAGE_FOLDER & EW_LANGUAGE_FILE(i)(2)))
			Next
		End If
	End Sub
	' Load language file description
	Private Function LoadFileDesc(File)
		LoadFileDesc = ""
		Set objDOM = ew_CreateXmlDom()
		objDOM.async = False
		objDOM.Load(File)
		If objDOM.ParseError.ErrorCode = 0 Then
			LoadFileDesc = GetNodeAtt(objDOM.documentElement, "desc")
		End If
	End Function
	' Load language file
	Private Sub Load(id)
		Dim i, sFileName, sName, sMenuId, sTblName, sFldName, sPhrase, sClient, PhraseList
		' Set up from file
		sFileName = GetFileName(id)
		If sFileName = "" Then
			sFileName = GetFileName(EW_LANGUAGE_DEFAULT_ID)
		End If
		If sFileName = "" Then Exit Sub
		Set objDOM = ew_CreateXmlDom()
		objDOM.async = False
		objDOM.Load(sFileName)
		If objDOM.ParseError.ErrorCode = 0 Then
			objDOM.setProperty "SelectionLanguage", "XPath"
		End If
	End Sub
	' Get language file name
	Private Function GetFileName(Id)
		Dim i
		If IsArray(EW_LANGUAGE_FILE) Then
			For i = 0 to UBound(EW_LANGUAGE_FILE)
				If EW_LANGUAGE_FILE(i)(0) = Id Then
					GetFileName = Server.MapPath(EW_LANGUAGE_FOLDER & EW_LANGUAGE_FILE(i)(2))
					Exit Function
				End If
			Next
		End If
		GetFileName = ""
	End Function
	' Get node attribute
	Private Function GetNodeAtt(Node, Att)
		If Not Node Is Nothing Then
			GetNodeAtt = Node.getAttribute(Att)
		Else
			GetNodeAtt = ""
		End If
	End Function
	' Get phrase
	Public Function Phrase(Name)
		Phrase = GetNodeAtt(objDOM.selectSingleNode("//global/phrase[@id='" & LCase(Name) & "']"), "value")
	End Function
	' Get project phrase
	Public Function ProjectPhrase(Id)
		ProjectPhrase = GetNodeAtt(objDOM.selectSingleNode("//project/phrase[@id='" & LCase(Id) & "']"), "value")
	End Function
	' Get menu phrase
	Public Function MenuPhrase(MenuId, Id)
		MenuPhrase = GetNodeAtt(objDOM.selectSingleNode("//project/menu[@id='" & MenuId & "']/phrase[@id='" & LCase(Id) & "']"), "value")
	End Function
	' Get table phrase
	Public Function TablePhrase(TblVar, Id)
		TablePhrase = GetNodeAtt(objDOM.selectSingleNode("//project/table[@id='" & LCase(TblVar) & "']/phrase[@id='" & LCase(Id) & "']"), "value")
	End Function
	' Get field phrase
	Public Function FieldPhrase(TblVar, FldVar, Id)
		FieldPhrase = GetNodeAtt(objDOM.selectSingleNode("//project/table[@id='" & LCase(TblVar) & "']/field[@id='" & LCase(FldVar) & "']/phrase[@id='" & LCase(Id) & "']"), "value")
	End Function
	' Output xml as JSON
	Public Function XmlToJSON(XPath)
		Dim NodeList, i, Id, Value, Str
		Set NodeList = objDOM.selectNodes(XPath)
		Str = "{"
		For i = 0 to NodeList.Length - 1
			Id = GetNodeAtt(NodeList.Item(i), "id")
			Value = GetNodeAtt(NodeList.Item(i), "value")
			Str = Str & """" & ew_JsEncode2(Id) & """:""" & ew_JsEncode2(Value) & ""","
		Next
		If Right(Str, 1) = "," Then Str = Left(Str, Len(Str)-1)
		Str = Str & "}" & vbCrLf
		XmlToJSON = Str
	End Function
	' Output all phrases as JSON
	Public Function AllToJSON()
		AllToJSON = "var ewLanguage = new ew_Language(" & XmlToJSON("//global/phrase") & ");"
	End Function
	' Output client phrases as JSON
	Public Function ToJSON()
		ToJSON = "var ewLanguage = new ew_Language(" & XmlToJSON("//global/phrase[@client='1']") & ");"
	End Function
End Class
'
'  Language class (end)
' ----------------------
' Create XML Dom object
Function ew_CreateXmlDom()
	On Error Resume Next
	Dim ProgId
	ProgId = Array("MSXML2.DOMDocument", "Microsoft.XMLDOM") ' Add other ProgID here
	Dim i
	For i = 0 To UBound(ProgId)
		Set ew_CreateXmlDom = Server.CreateObject(ProgId(i))
		If Err.Number = 0 Then Exit For
	Next
End Function
' Convert to full url
Function ew_ConvertFullUrl(url)
	Dim sUrl
	If url = "" Then
		ew_ConvertFullUrl = ""
	ElseIf Instr(url, "://") > 0 Then
		ew_ConvertFullUrl = url
	Else
		sUrl = ew_FullUrl
		ew_ConvertFullUrl = Mid(sUrl, 1, InStrRev(sUrl, "/")) & url
	End If
End Function
' Get full url
Function ew_FullUrl()
	ew_FullUrl = ew_DomainUrl() & Request.ServerVariables("SCRIPT_NAME")
End Function 
' Get domain url
Function ew_DomainUrl()
	Dim sUrl, bSSL, sPort, defPort
	sUrl = "http"
	bSSL = LCase(Request.ServerVariables("HTTPS")) <> "off"
	sPort = Request.ServerVariables("SERVER_PORT")
	If bSSL Then defPort = "443" Else defPort = "80"
	If sPort = defPort Then sPort = "" Else sPort = ":" & sPort
	If bSSL Then sUrl = sUrl & "s"
	sUrl = sUrl & "://"
	sUrl = sUrl & Request.ServerVariables("SERVER_NAME") & sPort
	ew_DomainUrl = sUrl
End Function
' Encode value for double-quoted Javascript string
Function ew_JsEncode2(val)
	val = Replace(val & "", "\", "\\")
	val = Replace(val, """", "\""")
'	val = Replace(val, vbCrLf, "\r\n")
'	val = Replace(val, vbCr, "\r")
'	val = Replace(val, vbLf, "\n")
	val = Replace(val, vbCrLf, "<br>")
	val = Replace(val, vbCr, "<br>")
	val = Replace(val, vbLf, "<br>")
	ew_JsEncode2 = val
End Function
' Adjust text for caption
Function ew_BtnCaption(Caption)
	Dim Min, Pad
	Min = 10
	ew_BtnCaption = Caption
	If Len(Caption) < Min Then
		Pad = Abs(Int((Min - Len(Caption))/2*-1))
		ew_BtnCaption = String(Pad, " ") & Caption & String(Pad, " ")
	End If
End Function
' *** DO NOT CHANGE
